/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.sac.converters;

/**
 *
 * @author MoShiTa
 */

import edu.upn.sigemfi.sac.bc.SolicitudCreditoDelegate;
import edu.upn.sigemfi.sac.be.EstadoDocumento;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;


public class EstadoDocumentoConverter implements Converter{


    public Object getAsObject(FacesContext arg0, UIComponent arg1, String string) throws ConverterException {
        SolicitudCreditoDelegate delegado = new SolicitudCreditoDelegate();
        if (string == null) {
            return null;
        }
        try {
            Long codigo = Long.parseLong(string);
            if (codigo != null) {
                return delegado.buscarEstadoDocumento(codigo);
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object object) throws ConverterException {
        if (object == null) {
            return null;
        }
        if (object instanceof EstadoDocumento) {
            EstadoDocumento es = (EstadoDocumento) object;
            return es.getIdEstadoDocumento().toString();
        }
        return null;
    }

}
